package com.ywm.dao.common.impl;

import com.ywm.common.database.BaseMapper;
import com.ywm.dao.common.BaseDao;
import org.springframework.beans.factory.annotation.Autowired;
import tk.mybatis.mapper.entity.Example;

import java.util.List;

public class BaseDaoImpl<T> implements BaseDao<T>{

	@Autowired
	private BaseMapper<T> baseMapper;
	
	@Override
	public int save(T t) {
		return baseMapper.insertSelective(t);
	}

	@Override
	public int updateById(T t) {
		return baseMapper.updateByPrimaryKeySelective(t);
	}

	@Override
	public int update(T t, Example e) {
		return baseMapper.updateByExampleSelective(t, e);
	}

	@Override
	public int delete(Long id) {
		return baseMapper.deleteByPrimaryKey(id);
	}

	@Override
	public T findOneById(Long id) {
		return baseMapper.selectByPrimaryKey(id);
	}

	@Override
	public T findOneByModel(T t) {
		return baseMapper.selectOne(t);
	}

	@Override
	public List<T> findList(T t) {
		return baseMapper.select(t);
	}

	@Override
	public int selectCount(T t) {
		return baseMapper.selectCount(t);
	}

}
